package com.sanpu.kxe.business.main.provider;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.sanpu.kxe.business.main.bean.AdviceOutput;
import com.sanpu.kxe.business.main.bean.BrowserInput;
import com.sanpu.kxe.business.main.bean.CertificationOldOutput;
import com.sanpu.kxe.business.main.bean.CertificationOutput;
import com.sanpu.kxe.business.main.bean.NoticeOutput;
import com.sanpu.kxe.business.main.bean.UserCenterOutput;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.view.AboutActivity;
import com.sanpu.kxe.business.main.view.AdviceDetailActivity;
import com.sanpu.kxe.business.main.view.AdviceListActivity;
import com.sanpu.kxe.business.main.view.AllApplicationActivity;
import com.sanpu.kxe.business.main.view.BrowserX5Activity;
import com.sanpu.kxe.business.main.view.CertificateHelpActivity;
import com.sanpu.kxe.business.main.view.CertificationActivity;
import com.sanpu.kxe.business.main.view.EventCenterActivity;
import com.sanpu.kxe.business.main.view.InviteFriendsActivity;
import com.sanpu.kxe.business.main.view.LinkfaceCheckActivity;
import com.sanpu.kxe.business.main.view.LinkfaceLivenessActivity;
import com.sanpu.kxe.business.main.view.LinkfaceOcrActivity;
import com.sanpu.kxe.business.main.view.MaterialLibraryActivity;
import com.sanpu.kxe.business.main.view.MyAwardActivity;
import com.sanpu.kxe.business.main.view.MyQrcodeActivity;
import com.sanpu.kxe.business.main.view.MyReferrerActivity;
import com.sanpu.kxe.business.main.view.MyScoreActivity;
import com.sanpu.kxe.business.main.view.MyWxInfoActivity;
import com.sanpu.kxe.business.main.view.NewsContentActivity;
import com.sanpu.kxe.business.main.view.NickNameModifyActivity;
import com.sanpu.kxe.business.main.view.NoticeActivity;
import com.sanpu.kxe.business.main.view.NoticeDetailsActivity;
import com.sanpu.kxe.business.main.view.OldCertificateOneActivity;
import com.sanpu.kxe.business.main.view.OldCertificateSecondActivity;
import com.sanpu.kxe.business.main.view.PartnerActivity;
import com.sanpu.kxe.business.main.view.PartnerTeamListActivity;
import com.sanpu.kxe.business.main.view.PromotePosterActivity;
import com.sanpu.kxe.business.main.view.PushDetailActivity;
import com.sanpu.kxe.business.main.view.PushListActivity;
import com.sanpu.kxe.business.main.view.PushMaterialActivity;
import com.sanpu.kxe.business.main.view.SetPayPwdSecondActivity;
import com.sanpu.kxe.business.main.view.SettingCenterActivity;
import com.sanpu.kxe.business.main.view.UserCenterActivity;
import com.sanpu.kxe.business.main.view.ZeroPurchActivity;
import com.sanpu.kxe.common.cache.CacheManage;
import com.sanpu.kxe.common.cache.CacheModel;
import com.sanpu.kxe.common.custom.SerializableHashMap;
import com.sanpu.kxe.common.interfaces.CommonConfig;
import com.sanpu.kxe.utils.IntentTool;

/**
 * Description：Main模块内部跳转类
 * Created by 薛勇军 on 2018/7/20.
 */

public class MainOpenProvider {

    private static MainOpenProvider instance;

    public static MainOpenProvider getInstance() {
        if (instance == null) {
            synchronized (MainOpenProvider.class) {
                if (instance == null) {
                    instance = new MainOpenProvider();
                }
            }
        }
        return instance;
    }

    /**
     * 证件认证
     */
    public void openCertificationActivity(Context context) {
        UserCenterOutput centerOutput = CacheManage.getInstance().getCache(CacheModel.USER_CENTER_KEY);
        if (centerOutput != null && TextUtils.equals(CommonConfig.AUTHEN_PASS, centerOutput.getChkSts())) {
            IntentTool.startActivity(context, CertificationActivity.class);
        } else {
            IntentTool.startActivity(context, LinkfaceOcrActivity.class);
        }
    }

    /**
     * 四要素认证
     */
    public void openCertificateThirdActivity(Context context, @NonNull CertificationOutput mOutput) {
        Intent intent = new Intent(context, CertificationActivity.class);
        intent.putExtra(MainConfig.INTENT_CERTIFICATION_INPUT, mOutput);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 四要素认证
     */
    public void openLinkfaceCheckActivity(Context context, @NonNull CertificationOutput mOutput) {
        Intent intent = new Intent(context, LinkfaceCheckActivity.class);
        intent.putExtra(MainConfig.INTENT_CERTIFICATION_INPUT, mOutput);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 活体检测
     */
    public void openLinkfaceLivenessActivity(Context context, @NonNull CertificationOutput mOutput) {
        Intent intent = new Intent(context, LinkfaceLivenessActivity.class);
        intent.putExtra(MainConfig.INTENT_CERTIFICATION_INPUT, mOutput);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 老流程第一步
     */
    public void openOldCertificateOneActivity(Context context, SerializableHashMap hashMap,
                                              CertificationOutput mOutput, boolean isComeFromNews, boolean isFinish) {
        Intent intent = new Intent(context, OldCertificateOneActivity.class);
        intent.putExtra(MainConfig.INTENT_CERTIFICATION_INPUT, mOutput);
        intent.putExtra(MainConfig.INTENT_COME_FROM_NEWS, isComeFromNews);
        Bundle bundle = new Bundle();
        bundle.putSerializable(MainConfig.INTENT_CERTIFICATE_FILE, hashMap);
        intent.putExtras(bundle);
        IntentTool.startActivity(context, intent, isFinish);
    }

    /**
     * 老流程第二步
     */
    public void openOldCertificateSecondActivity(Context context, @NonNull CertificationOldOutput mOutput,
                                                 SerializableHashMap hashMap, boolean isComeFromNews) {
        Intent intent = new Intent(context, OldCertificateSecondActivity.class);
        intent.putExtra(MainConfig.INTENT_CERTIFICATION_OLD_INPUT, mOutput);
        intent.putExtra(MainConfig.INTENT_COME_FROM_NEWS, isComeFromNews);
        if (hashMap != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable(MainConfig.INTENT_CERTIFICATE_FILE, hashMap);
            intent.putExtras(bundle);
        }
        IntentTool.startActivity(context, intent);
    }

    /**
     * 认证照片示例
     *
     * @param currentType 照片类型
     */
    public void openCertificateHelpActivity(Context context, String currentType) {
        Intent intent = new Intent();
        intent.setClass(context, CertificateHelpActivity.class);
        intent.putExtra(MainConfig.INTENT_CURRENT_TYPE, currentType);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 消息中心
     */
    public void openNoticeActivity(Context context) {
        IntentTool.startActivity(context, NoticeActivity.class);
    }

    /**
     * 消息详情
     */
    public void openNoticeDetailsActivity(Context context, NoticeOutput mOutput, boolean isMarquee) {
        Intent intent = new Intent();
        intent.setClass(context, NoticeDetailsActivity.class);
        intent.putExtra(MainConfig.INTENT_NOTICE, mOutput);
        intent.putExtra(MainConfig.INTENT_ISMARQUEE, isMarquee);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 活动中心
     */
    public void openEventCenterActivity(Context context) {
        IntentTool.startActivity(context, EventCenterActivity.class);
    }

    /**
     * 我的积分
     */
    public void openMyScoreActivity(Context context) {
        IntentTool.startActivity(context, MyScoreActivity.class);
    }

    /**
     * 个人中心
     */
    public void openUserCenterActivity(Context context) {
        IntentTool.startActivity(context, UserCenterActivity.class);
    }

    /**
     * 在线咨询
     */
    public void openAboutActivity(Context context) {
        IntentTool.startActivity(context, AboutActivity.class);
    }

    /**
     * 合伙人
     */
    public void openPartnerActivity(Context context) {
        IntentTool.startActivity(context, PartnerActivity.class);
    }

    /**
     * 合伙人团队详情
     */
    public void openPartnerTeamListActivity(Context context) {
        IntentTool.startActivity(context, PartnerTeamListActivity.class);
    }

    /**
     * 推荐人
     */
    public void openMyReferrerActivity(Context context) {
        IntentTool.startActivity(context, MyReferrerActivity.class);
    }

    /**
     * 我的微信
     */
    public void openMyWxInfoActivity(Context context) {
        IntentTool.startActivity(context, MyWxInfoActivity.class);
    }

    /**
     * 修改昵称
     */
    public void openNickNameModifyActivity(Context context, @NonNull String nickName) {
        Intent builder = new Intent(context, NickNameModifyActivity.class);
        builder.putExtra(MainConfig.INTENT_NICKNAME, nickName);
        IntentTool.startActivity(context, builder);
    }

    /**
     * 设置中心
     */
    public void openSettingCenterActivity(Context context) {
        IntentTool.startActivity(context, SettingCenterActivity.class);
    }

    /**
     * 浏览器
     *
     * @param context     上下文
     * @param title       标题，如不传就用webview的标题
     * @param url         访问地址
     * @param referrer    签名头
     * @param content     html串（url为空时）
     * @param showTitle   是否显示标题   true 显示 false 不显示
     * @param showPreLoad 是否显示加载框 true 显示 false 不显示
     */
    public void openBrowserX5Activity(Context context, String title, String url, String referrer,
                                      String content, boolean showTitle, boolean showPreLoad) {
        BrowserInput input = new BrowserInput();
        input.setTitle(title);
        input.setUrl(url);
        input.setReferrer(referrer);
        input.setContent(content);
        input.setShowTitle(showTitle);
        input.setShowPreLoad(showPreLoad);
        Intent intent = new Intent();
        intent.setClass(context, BrowserX5Activity.class);
        intent.putExtra(MainConfig.INTENT_BROWSER_INPUT, input);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 传入html串访问浏览器
     * 显示标题栏，不显示加载框
     */
    public void openBrowserX5Activity(Context context, String content) {
        openBrowserX5Activity(context, null, null, null, content, true, false);
    }

    /**
     * 传入url串访问浏览器
     * 显示标题栏，显示加载框
     */
    public void openBrowserX5Activity(Context context, String title, String url) {
        openBrowserX5Activity(context, title, url, null, null, true, true);
    }

    /**
     * 传入签名头和url串访问浏览器
     * 显示标题栏，不显示加载框
     */
    public void openBrowserX5Activity(Context context, String title, String url, String referrer) {
        openBrowserX5Activity(context, title, url, referrer, null, true, false);
    }

    /**
     * 传入url串访问浏览器, 显示标题栏
     *
     * @param showPreLoad 是否显示加载框由
     */
    public void openBrowserX5Activity(Context context, String url, boolean showPreLoad) {
        openBrowserX5Activity(context, null, url, null, null, true, showPreLoad);
    }

    /**
     * 传入url串访问浏览器
     *
     * @param showTitle   是否显示标题栏，
     * @param showPreLoad 是否显示加载框由
     */
    public void openBrowserX5Activity(Context context, String url, boolean showTitle, boolean showPreLoad) {
        openBrowserX5Activity(context, null, url, null, null, showTitle, showPreLoad);
    }

    /**
     * 打开我的奖励
     */
    public void openMyAwardActivity(Context context) {
        IntentTool.startActivity(context, MyAwardActivity.class);
    }

    /**
     * 打开全部应用
     */
    public void openAllApplicationActivity(Context context) {
        IntentTool.startActivity(context, AllApplicationActivity.class);
    }

    /**
     * 打开0元购机
     */
    public void openZeroPurchActivity(Context context, String url) {
        Intent intent = new Intent();
        intent.setClass(context, ZeroPurchActivity.class);
        intent.putExtra(MainConfig.INTENT_ZEROPURCHASEURL, url);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 打开推广海报朋友圈
     */
    public void openPromotePosterActivity(Context context) {
        IntentTool.startActivity(context, PromotePosterActivity.class);
    }

    /**
     * 打开地推物料
     */
    public void openPushMaterialActivity(Context context) {
        IntentTool.startActivity(context, PushMaterialActivity.class);
    }

    /**
     * 打开地推物料列表
     */
    public void openPushListActivity(Context context, String name, String type) {
        Intent intent = new Intent(context, PushListActivity.class);
        intent.putExtra(MainConfig.INTENT_MATERIAL_NAME, name);
        intent.putExtra(MainConfig.INTENT_MATERIAL_TYPE, type);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 打开地推物料详情
     */
    public void openPushDetailActivity(Context context, String name, String path) {
        Intent intent = new Intent(context, PushDetailActivity.class);
        intent.putExtra(MainConfig.INTENT_MATERIAL_NAME, name);
        intent.putExtra(MainConfig.INTENT_MATERIAL_PATH, path);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 打开我的二维码
     */
    public void openMyQrcodeActivity(Context context) {
        IntentTool.startActivity(context, MyQrcodeActivity.class);
    }

    /**
     * 打开咨询内容
     */
    public void openNewsContentActivity(Context context, String url, String title, String content, String picturePath) {
        Intent intent = new Intent();
        intent.setClass(context, NewsContentActivity.class);
        intent.putExtra(MainConfig.INTENT_NEWS_URL, url);
        intent.putExtra(MainConfig.INTENT_SHARETITLE, title);
        intent.putExtra(MainConfig.INTENT_SHARECONTENT, content);
        intent.putExtra(MainConfig.INTENT_SHAREPICTURE, picturePath);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 了难中心提交记录
     */
    public void openAdviceListActivity(Context context) {
        IntentTool.startActivity(context, AdviceListActivity.class, true);
    }

    /**
     * 了难中心提交详情
     */
    public void openAdviceDetailActivity(Context context, AdviceOutput output) {
        Intent intent = new Intent(context, AdviceDetailActivity.class);
        intent.putExtra(MainConfig.INTENT_ADVICE_ENTITY, output);
        IntentTool.startActivity(context, intent);
    }

    /**
     * 设置支付密码第二步
     */
    public void openSetPayPwdSecondActivity(Context context, String password, int requestCode) {
        Intent builder = new Intent(context, SetPayPwdSecondActivity.class);
        builder.putExtra(MainConfig.INTENT_PASSWORD, password);
        IntentTool.startActivityForResult(context, builder, requestCode);
    }

    /**
     * 邀请好友
     */
    public void openInviteFriendsActivity(Context context) {
        IntentTool.startActivity(context, new Intent(context, InviteFriendsActivity.class));
    }

    /**
     * 素材库
     */
    public void openMaterialLibraryActivity(Context context) {
        IntentTool.startActivity(context, new Intent(context, MaterialLibraryActivity.class));
    }
}
